<%@ include file="../system/HeaderStrutsForm.jsp" %>
<html>
  <head>

    <bean:message key="page.css"/>
    <bean:message key="page.script"/>
  </head>
  <center>
    <body>
      <table class="mainTable" style='width:99%;'>
        <tr>
          <td>
            <html:form 
                action="Usuario/EmailForm.do"
                method="POST"
                onsubmit="return validar();"
                scope="session"
                styleClass="baseForm"
                target="_self">


              <table class="bannerTable" style='width:99%;'>
                <tr>
                  <td class=tableHeader>
                    Cadastro de E-mail
                  </td>
                </tr>
              </table>
              <table class="messageTable" style='width:99%;'>
                <tr>
                  <td class="messageHeader">
                    <bean:message key="div.campos*"/>
                    <html:errors/>
                  </td>
                </tr>
              </table>
              <table class="itemTable" style='width:99%;'>
                <tr>
                  <td class="formLabel">
                    <span class="spamFormLabel" >
                      E-mail
                      <img 
                          src='../img/required.gif'
                          border='0'
                          alt='Not Null'
                          style='cursor:hand'>


                      &nbsp;
                    </span>
                  </td>
                  <td class="formField">
                    <html:text 
                        property="emil_endereco"
                        onkeydown="javascript:toUpperCase(this);"
                        styleClass="baseField"
                        size="100"
                        maxlength="100"/>
                  </td>
                </tr>
              </table>
              <table class="buttonTable" style='width:99%;'>
                <tr>
                  <td class="buttonItem">
                    <html:submit 
                        accesskey="s"
                        onclick="javascript:document.forms[0].emil_endereco.value+='%';"
                        styleClass="baseButton"
                        property="select_action">


                      <bean:message 
                          bundle="ApplicationResources"
                          key="jsp.select"/>
                    </html:submit>
                    <html:submit 
                        accesskey="i"
                        styleClass="baseButton"
                        property="insert_action">


                      <bean:message 
                          bundle="ApplicationResources"
                          key="jsp.insert"/>
                    </html:submit>
                    <html:submit 
                        accesskey="r"
                        onclick="return confirmSubmit('');"
                        styleClass="baseButton"
                        property="resetfull_action">


                      <bean:message 
                          bundle="ApplicationResources"
                          key="jsp.reset"/>
                    </html:submit>
                  </td>
                </tr>
              </table>
            </html:form>

            <%
            {
              %>
              <form class="baseForm" >
                <table class="bannerTable" style=width:99%;>
                  <tr>
                    <td class="tableHeader">
                      Lista de E-mails
                    </td>
                  </tr>
                </table>
                <table 
                    id="TRbl_report_Email"
                    class="reportTable"
                    style=width:99%;
                     >

                  <%
                  int counterbl_report_Email=0;
                  %>
                  <%
                  {
                    br.com.werp.suporte.dbobj.table.Email t_email = new br.com.werp.suporte.dbobj.table.Email();
                    java.util.Vector res_Email = null;
                    br.com.werp.suporte.Usuario.EmailActionForm EmailActionForm = (br.com.werp.suporte.Usuario.EmailActionForm)session.getAttribute("EmailActionForm");
                    if(EmailActionForm!=null && (EmailActionForm.getEmil_endereco()!=null && EmailActionForm.getEmil_endereco().length()>0)) {
                      com.egen.util.jdbc.JdbcUtil j = null;
                      try {
                        j = new com.egen.util.jdbc.JdbcUtil();
                        String[][] select =  null;
                        Object[][] where = null;
                        where = new Object[][] {{"emil_endereco","=",EmailActionForm.getEmil_endereco()}};
                        String[] groupby =  null;
                        String[] having =  null;
                        String[] order = {};
                        res_Email = j.select(t_email,select,where,groupby,having,order);
                      } catch (Exception e){
                        res_Email = null;
                      } finally {
                      if(j!=null){j.close();}
                    }
                  } else {
                    res_Email = null;
                  }
                  if (res_Email!=null && res_Email.size()>0) {
                    if ( ((String)request.getParameter("_ordered"))!=null && ((String)request.getParameter("_ordered")).length()>0 ) {
                      boolean reverse = false;
                      if ( ((String)request.getParameter("_reverse"))!=null && ((String)request.getParameter("_reverse")).length()>0 && ((String)request.getParameter("_reverse")).equals("true") ){
                        reverse = true;
                      }
                      try {
                        res_Email = com.egen.util.text.Sort.execute(res_Email,((String)request.getParameter("_ordered")),reverse);
                      } catch (Exception e) {}
                    }
                    int emil_id =  0;
                    java.lang.String emil_endereco =  null;
                    int i_bl_report_Email = 0;
                    t_email = (br.com.werp.suporte.dbobj.table.Email)res_Email.elementAt(i_bl_report_Email);
                    emil_id = t_email.getEmil_id();
                    emil_endereco = t_email.getEmil_endereco()==null?"":t_email.getEmil_endereco();
                    %>
                    <tr class="reportHeader" >
                      <td >
                        <span 
                            class="spamHeaderLabel"
                            style="text-align:left;width:100%;">

                          e-mail
                        </span>
                      </td>
                    </tr>
                    <%
                    while (i_bl_report_Email<res_Email.size()){
                      counterbl_report_Email++;
                      String style="";
                      if (!((i_bl_report_Email%2)!=0)) {
                        style="class=rowColor";
                      } else {
                        style="class=rowBlank";
                      }
                      %>
                      <tr 
                          <%=
                          style
                          %>
                          id='TRbl_report_Email<%=counterbl_report_Email%>'
                      >

                        <td class="reportcolumn"  >
                          <a 
                              href="../Usuario/EmailDetalheForm.do?select_action=&emil_id=<%= emil_id %>&emil_endereco=<%= emil_endereco %>"
                              target="_self"
                              STYLE="cursor:hand">


                            <span 
                                class="spamColumnLabel"
                                style="text-align:left;">

                              <%= emil_endereco %>
                            </span>
                          </a>
                        </td>
                      </tr>
                      <%
                      if (++i_bl_report_Email >= res_Email.size()) {
                        break;
                      }
                      t_email = (br.com.werp.suporte.dbobj.table.Email)res_Email.elementAt(i_bl_report_Email);
                      emil_id = t_email.getEmil_id();
                      emil_endereco = t_email.getEmil_endereco()==null?"":t_email.getEmil_endereco();
                    }
                  }
                }
                %>
              </table>
            </form>
            <%
          }
          %>
        </td>
      </tr>
    </table>
  </body>
</center>
</html>
